package com.web.portal.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;


import org.hibernate.validator.Pattern;
import org.hibernate.validator.Size;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Email;

@Entity
@Table(name = "faculty")
public class Faculty implements Serializable,Comparable<Faculty> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String id;

	private byte[] image;

	private String firstName;

	private String lastName;
	
	private String description;

	private String email;

	private String phone;

	private String research;
	private byte[] map;
	private String position;

	

	@GeneratedValue
	@Id
	@Column(name = "id")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	@Lob
	@Column(name = "image")
	public byte[] getImage() {
		return image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

	@NotBlank(message = "Field value should not be null")
	@Column(name = "first_name")
	@Pattern(regex = "[a-z-A-Z]*", message = "First name has invalid characters")
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "last_name")
	@NotBlank(message = "Field value should not be null")
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(name = "description")
	@NotBlank(message = "Field value should not be null")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "email")
	
	@Email(message = "You provided an invalid email")
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Size(min = 10, max = 10, message = "Size should be ten : 4537653456")
	@Column(name = "phone_number")
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "research")
	public String getResearch() {
		return research;
	}

	public void setResearch(String research) {
		this.research = research;
	}
	@Lob
	@Column(name = "location_map")
	public byte[] getMap() {
		return map;
	}

	public void setMap(byte[] map) {
		this.map = map;
	}
	@Column (name ="position")
	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}
	/*
	 * possilbe this should be done on Pojo instead (keep it for refactoring)
	 */

	public int compareTo(Faculty otherFaculty) {
		String firstName=otherFaculty.getFirstName();
		int diff=this.firstName.compareToIgnoreCase(firstName);
		/*
		 * firstname
		 */
		if(diff!=0){
			return diff;
		}
		/*
		 * if first name equal then this
		 **/
		 else{
		 
		 
		return this.lastName.compareToIgnoreCase(otherFaculty.lastName);
	}
	}
}
